##
# makefile - Created by Timothy Morey on 1/27/2012.
#

OBJS = cl-args.o \
       client.o \
       communication-queue.o \
       forest.o \
       main.o \
       messages.o \
       mutex.o \
       nc_writer.o \
       server.o \
       simulator.o \
       socket-utils.o

NVCC_OPTS = -arch=compute_10
GCC_OPTS = -c -g -G -I/usr/include/libxml2
LINK_OPTS = -g -G -lpthread -lnetcdf -lxml2

COMPILE = nvcc $(NVCC_OPTS) $(GCC_OPTS)

forest : $(OBJS)
	nvcc $(OBJS) $(LINK_OPTS) -o forest

cl-args.o : ../nvn/nvn-common/cl-args.c ../nvn/nvn-common/cl-args.h
	$(COMPILE) ../nvn/nvn-common/cl-args.c

client.o : ../nvn/nvn-common/client.c ../nvn/nvn-common/client.h \
           ../nvn/nvn-common/communication-queue.h \
           ../nvn/nvn-common/socket-utils.h
	$(COMPILE) ../nvn/nvn-common/client.c

communication-queue.o : ../nvn/nvn-common/communication-queue.c ../nvn/nvn-common/communication-queue.h \
                        ../nvn/nvn-common/mutex.h
	$(COMPILE) ../nvn/nvn-common/communication-queue.c

forest.o : forest.cu forest.cuh
	$(COMPILE) forest.cu

main.o : main.cpp \
         simulator.h \
         ../nvn/nvn-common/cl-args.h \
         ../nvn/nvn-common/client.h \
         ../nvn/nvn-common/messages.h \
         ../nvn/nvn-common/server.h
	$(COMPILE) main.cpp

messages.o : ../nvn/nvn-common/messages.c ../nvn/nvn-common/messages.h
	$(COMPILE) ../nvn/nvn-common/messages.c

mutex.o : ../nvn/nvn-common/mutex.c ../nvn/nvn-common/mutex.h
	$(COMPILE) ../nvn/nvn-common/mutex.c

nc_writer.o : nc_writer.cpp nc_writer.h
	$(COMPILE) nc_writer.cpp

server.o : ../nvn/nvn-common/server.c ../nvn/nvn-common/server.h \
           ../nvn/nvn-common/communication-queue.h \
           ../nvn/nvn-common/socket-utils.h
	$(COMPILE) ../nvn/nvn-common/server.c

socket-utils.o : ../nvn/nvn-common/socket-utils.c ../nvn/nvn-common/socket-utils.h
	$(COMPILE) ../nvn/nvn-common/socket-utils.c

simulator.o : simulator.cu simulator.h \
              forest.cuh \
              nc_writer.h \
              ../common/cuda.cuh \
              ../nvn/nvn-common/client.h
	$(COMPILE) simulator.cu

clean :
	rm -v -f parts *.o *~ *.gch
